//
//  ViewController.m
//  模糊效果
//
//  Created by yq on 2022/6/16.
//

#import "ViewController.h"
#import "CoreImageViewController.h"
#import "ImageEffectsViewController.h"
#import "VisualEffectViewController.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataSource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView.tableFooterView = [[UIView alloc] init];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.text = self.dataSource[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        CoreImageViewController *coreImageVC = [[CoreImageViewController alloc]init];
        [self.navigationController pushViewController:coreImageVC animated:YES];
    }else if (indexPath.row == 1) {
        ImageEffectsViewController *imageEffectsVC = [[ImageEffectsViewController alloc] init];
        [self.navigationController pushViewController:imageEffectsVC animated:YES];
    }else if (indexPath.row == 2) {
        VisualEffectViewController *visualEffectVC = [[VisualEffectViewController alloc] init];
        [self.navigationController pushViewController:visualEffectVC animated:YES];
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (NSArray *)dataSource {
    if (!_dataSource) {
        _dataSource = @[@"CoreImage", @"UIImage+ImageEffects", @"UIVisualEffectView"];
        
    }
    return _dataSource;
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}
@end
